#include "BankAccount.hh"
#include <fstream>
#include <iomanip>
#include <iostream>



BankAccount::BankAccount(const std::string& id, const std::string& owner, double initialBalance)
    : accountId(id), ownerName(owner), balance(initialBalance) {
    transactions.reserve(100); 
}

void BankAccount::addTransaction(const Transaction& transaction) {
    transactions.push_back(transaction);
}

bool BankAccount::generateReport(const std::string& filename) const {
    std::ofstream file(filename);
    if (!file.is_open()) {
        std::cout << "Error: Could not create report file: " << filename << "\n";
        return false;
    }

    file << "Transaction Report for Account: " << accountId << "\n";
    file << "Account Type: " << getAccountType() << "\n";
    file << "Owner: " << ownerName << "\n";
    file << "Balance: " << std::fixed << std::setprecision(2) << balance << "\n\n";
    file << "Transactions:\n";
    file << std::left << std::setw(10) << "ID"
         << std::setw(20) << "Date"
         << std::setw(15) << "Type"
         << std::setw(10) << "Amount"
         << "Note\n";
    file << std::string(65, '-') << "\n";

    for (const auto& t : transactions) {
        file << std::left << std::setw(10) << t.getTransactionId()
             << std::setw(20) << t.getDate()
             << std::setw(15) << t.getType()
             << std::fixed << std::setprecision(2) << std::setw(9) << t.getAmount()
             << t.getNote() << "\n";
    }

    file.close();
    std::cout << "Report generated as " << filename << "\n";
    return true;
}



